<template>
	<view>
		<web-view :src="pdfUrl"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pdfUrl: '',
				from: '',
				viewerUrl: "/hybrid/html/web/viewer.html"
			}
		},
		onLoad(option) {
			this.getDetailData({
				fId: window.location.href.split("=")[1]
			})
			uni.setNavigationBarTitle({
				title: '人员信息'
			})





		},
		methods: {
			// 详情
			getDetailData(data) {

				var that = this;
				that.fileList = [];

				that.$http.getTesterPDF(data).then(res => {
					if (res.errcode == 0) {

						let fileUrl = encodeURIComponent(res.data.url) // encodeURIComponent 函数可把字符串作为 URI 组件进行编码。
						this.pdfUrl = this.viewerUrl + '?file=' + fileUrl
						// this.pdfUrl = this.viewerUrl + '?file=' + fileUrl
							
					} else {
						uni.showToast({
							title: "请求失败",
							icon: 'none',
							duration: 2000
						});
					}

				}, (err) => {
					uni.showToast({
						title: "接口报错",
						icon: 'none',
						duration: 2000
					});
				})

			},
			downloadPdfClick() {
				// 下载情景1:h5内嵌app,通过分享给朋友的方式进行下载
				if (this.from == 'app') {
					let item = 'http://自己的域名/hybrid/html/web/pdf.html?shareUrl=' + encodeURIComponent(this.bgUrl) +
						'&shareTitle=PDF文件';
					window.open(item);
					return;

				} else if (this.from == 'wx wq') {
					// 下载情景2:h5内嵌微信小程序,从h5页面跳转到小程序页面后,然后通过调用小程序原生API进行下载
					// 注意: 先要引入微信jssdk  [命令: npm install jweixin-module]
					// this.$wx.miniProgram.navigateTo({
					// 	url: '/pages/pdf/pdf_download?pdf='+ encodeURIComponent(this.bgUrl) //小程序页面链接
					// });
				}

			}
		}
	}
</script>

<style>

</style>
